package cn.edu.xcu.ckl.base;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import cn.edu.xcu.ckl.R;

public abstract class BaseActivity  extends AppCompatActivity {
    protected Activity mBaseActivity;
    protected Toolbar toolbar;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mBaseActivity = this;
        setContentView(getLayoutResId());

        //返回点击事件
        toolbar = findViewById(R.id.toolbar);
        if (null != toolbar) {
            toolbar.setNavigationOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    finish();
                }
            });
        }

        initView();

        setListener();
        initData();


    }


    /**
     * 加载布局文件
     */
    protected abstract int getLayoutResId();

    /**
     * 初始化控件
     */
    protected  abstract  void initView();

    /**
     * 点击事件
     */
    protected abstract void setListener();

    /**
     * 初始化数据
     */
    protected abstract void initData();


    protected void showToast(String msg) {
        Toast.makeText(mBaseActivity, msg, Toast.LENGTH_SHORT).show();
    }
}
